package servlets;

import java.io.IOException;
import java.util.List;

import javax.naming.NamingException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import delegate.BusinessDelegate;
import dtos.VentaDTO;

/**
 * Servlet implementation class EstadoEntrega
 */
@WebServlet("/EstadoEntrega")
public class EstadoEntrega extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public EstadoEntrega() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		HttpSession session = request.getSession();
		String login = (String)session.getAttribute("usuario");
		
		String jsp = "estadoEntrega.jsp";
		
		try {
			List<VentaDTO> ventas = BusinessDelegate.getInstancia().obtenerVentas(login);
			request.setAttribute("ventas", ventas);
			
		} catch (NamingException e) {
			e.printStackTrace();
			request.setAttribute("error", e.getMessage());
			jsp = "/error.jsp";
		}
		catch (Exception e) {
			request.setAttribute("error", e.getMessage());
			jsp = "/error.jsp";
		}
		
		RequestDispatcher dispatcher = request.getRequestDispatcher(jsp);
		dispatcher.forward(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		this.doGet(request, response);
	}

}
